package utils.impl;

import entities.GeneralId;
import utils.BaseManager;
import utils.IGeneralIdManager;

import javax.ejb.Stateless;

/**
 * Created with IntelliJ IDEA.
 * User: NGUYEN VAN NHAN
 * Date: 9/20/14
 * Time: 1:33 PM
 * Long Van Soft Solution Sjc.
 * To change this template use File | Settings | File Templates.
 */
@Stateless
public class GeneralIdManager extends BaseManager implements IGeneralIdManager{
    @Override
    public String getId(Class classs) {
        GeneralId generalId = find(GeneralId.class, classs.getClass());
        if (null == generalId){
            generalId = new GeneralId();
            generalId.setId(classs.getName());
            generalId.setValue(0);
            create(generalId);
        }
        int id = generalId.getValue();
        generalId.setValue(++id);
        edit(generalId);
        return String.valueOf(id);
    }

    @Override
    public String getClassName() {
        return getClass().getName();
    }
}
